import 'dart:developer';

import 'package:dio/dio.dart';



class PrintLogInterceptor extends InterceptorsWrapper {

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {

    log("\nrequest ------>");
    options.headers?.forEach((key, value) {
      log("请求头：key=$key value = ${value.toString()}");
    });
    log("path: ${options.uri}");
    log("method: ${options.method}");
    log("data: ${options.data}");
    log("queryParameters: ${options.queryParameters.toString()}");
    log("<------- request\n");

    super.onRequest(options, handler);
  }


  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {

    log("\nrponse ------>");
    log("path: ${response.realUri}");
    log("headers: ${response.headers.toString()}");
    log("statusMessage: ${response.statusMessage}");
    log("statusCode: ${response.statusCode}");
    log("extra: ${response.extra.toString()}");
    log("data: ${response.data.toString()}");

    log("<------- rponse\n");

    super.onResponse(response, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {

    print("\nerror ------>");
    print("\nerror: ${err.toString()}");
    print("<------- error\n");

    super.onError(err, handler);
  }
}